﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:MahApps.Metro.Controls"
                    xmlns:Converters="clr-namespace:MahApps.Metro.Converters">

    <Converters:ToUpperConverter x:Key="ToUpperConverter" />

    <Style x:Key="MetroGroupBox"
           TargetType="{x:Type GroupBox}">
        <Setter Property="Margin"
                Value="5" />
        <Setter Property="Padding"
                Value="5" />
        <Setter Property="Foreground"
                Value="{DynamicResource BlackBrush}" />
        <Setter Property="Background"
                Value="{DynamicResource AccentColorBrush}" />
        <Setter Property="BorderBrush"
                Value="{DynamicResource AccentColorBrush}" />
        <Setter Property="Controls:ControlsHelper.HeaderFontSize"
                Value="{DynamicResource ContentFontSize}" />
        <Setter Property="Controls:ControlsHelper.GroupBoxHeaderForeground"
                Value="{x:Null}" />
        <Setter Property="HeaderTemplate">
            <Setter.Value>
                <DataTemplate>
                    <ContentPresenter Content="{Binding RelativeSource={RelativeSource AncestorType={x:Type GroupBox}}, Path=Header, Mode=OneWay, Converter={StaticResource ToUpperConverter}}">
                        <TextElement.Foreground>
                            <MultiBinding Converter="{x:Static Converters:BackgroundToForegroundConverter.Instance}">
                                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type GroupBox}}"
                                         Path="Background"
                                         Mode="OneWay" />
                                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type GroupBox}}"
                                         Path="(Controls:ControlsHelper.GroupBoxHeaderForeground)"
                                         Mode="OneWay" />
                            </MultiBinding>
                        </TextElement.Foreground>
                    </ContentPresenter>
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GroupBox}">
                    <Grid x:Name="GroupBoxRoot">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Border Grid.Row="0"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="1">
                            <ContentPresenter Margin="{TemplateBinding Padding}"
                                              TextElement.FontSize="{TemplateBinding Controls:ControlsHelper.HeaderFontSize}"
                                              TextElement.FontStretch="{TemplateBinding Controls:ControlsHelper.HeaderFontStretch}"
                                              TextElement.FontWeight="{TemplateBinding Controls:ControlsHelper.HeaderFontWeight}"
                                              ContentSource="Header"
                                              RecognizesAccessKey="True" />
                        </Border>
                        <Border Grid.Row="1"
                                Background="Transparent"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="1,0,1,1">
                            <ContentPresenter Margin="{TemplateBinding Padding}"
                                              Content="{TemplateBinding Content}"
                                              ContentTemplate="{TemplateBinding ContentTemplate}"
                                              Cursor="{TemplateBinding Cursor}" />
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
